<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="<%=request.getContextPath() %>/static/common/js/jquery.min.js"></script> 
<title>无标题文档</title>
<style type="text/css">
	ul {
		list-style:none;
	}
</style>
<script type="text/javascript">
	$(function() {
		$(":checkbox").bind("click",function() {
			// 判断复选框是否选中
			//alert($(this).is(":checked"));
			//alert($(this).next().next().find("input:checkbox").length);
			$(this).next().next().find("input:checkbox").prop("checked",$(this).is(":checked"));
		});
		$(".child > li").find(":checkbox").bind("click",function() {
			// 找到当前节点上面的父节点的父节点下面所有的选中的复选框个数
			var count = $(this).parent().parent().find("input:checked").length;
			//alert($(this).parent().parent().parent().children(":checkbox").attr("name"));
			var $parentNode = $(this).parent().parent().parent().children(":checkbox");
			if(count==0) {
				$parentNode.prop("checked",false);
			} else {
				$parentNode.prop("checked",true);
			}
		});
		
		// 点击授权按钮操作
		$(":button").bind("click",function() {
			// 获取所有选中的复选框对象数组
			var menuString="";
			$("ul").find("input:checked").each(function() {
				menuString+=$(this).val()+",";
			});
			menuString = menuString.substr(0,menuString.length-1);
			location.href="SysServlet?command=grant&menuString="+menuString+"&roleId=${param.roleId}";
		});
	});
</script>
</head>
<body>
	<div class="place">
    <span>位置：角色授权页面</span>
    </div>	
    <ul>
		<c:forEach items="${mainMenus }" var="mainMenu">
				<li>
					<c:set var="flag" value="true" />
					<c:forEach items="${roleMainMenus }" var="roleMainMenu">
						<c:if test="${roleMainMenu.rightId==mainMenu.rightId }">
							<input type="checkbox" checked="checked" name="main" id="main${mainMenu.rightId }" value="${mainMenu.rightId }" /><label for="main${mainMenu.rightId }">${mainMenu.rightname}</label>
							<c:set var="flag" value="false" />
						</c:if>
					</c:forEach>
					<c:if test="${flag}">
						<input type="checkbox" name="main" id="main${mainMenu.rightId }" value="${mainMenu.rightId }" /><label for="main${mainMenu.rightId }">${mainMenu.rightname}</label>
					</c:if>
					<ul class="child">
						<c:forEach items="${childMenus }" var="childMenu">
							<c:if test="${childMenu.parentId == mainMenu.rightId }">
								<li>
									<c:set var="flag" value="true" />
									<c:forEach items="${roleChildMenus }" var="roleChildMenu">
										<c:if test="${roleChildMenu.rightId== childMenu.rightId }">
											<input type="checkbox" checked="checked" name="child" id="child${childMenu.rightId }" value="${childMenu.rightId }" /><label for="child${childMenu.rightId }">${childMenu.rightname}</label>
											<c:set var="flag" value="false" />
										</c:if>
									</c:forEach>
									<c:if test="${flag }">
										<input type="checkbox" name="child" id="child${childMenu.rightId }" value="${childMenu.rightId }" /><label for="child${childMenu.rightId }">${childMenu.rightname}</label>
									</c:if>
								</li>
							</c:if>
						</c:forEach>
					</ul>	
				</li>
			</c:forEach>
		</ul>
		<input type="button" value="授权" />
</body>
</html>
<%--  <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色授权操作</title>
<style type="text/css">
	ul {
		list-style:none;
	}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
	$(function() {
		$(":checkbox").bind("click",function() {
			// 判断复选框是否选中
			//alert($(this).is(":checked"));
			//alert($(this).next().next().find("input:checkbox").length);
			$(this).next().next().find("input:checkbox").prop("checked",$(this).is(":checked"));
		});
		
		$(".child > li").find(":checkbox").bind("click",function() {
			// 找到当前节点上面的父节点的父节点下面所有的选中的复选框个数
			var count = $(this).parent().parent().find("input:checked").length;
			//alert($(this).parent().parent().parent().children(":checkbox").attr("name"));
			var $parentNode = $(this).parent().parent().parent().children(":checkbox");
			if(count==0) {
				$parentNode.prop("checked",false);
			} else {
				$parentNode.prop("checked",true);
			}
		});
		
		// 点击授权按钮操作
		$(":button").bind("click",function() {
			// 获取所有选中的复选框对象数组
			var menuString="";
			$("ul").find("input:checked").each(function() {
				menuString+=$(this).val()+",";
			});
			menuString = menuString.substr(0,menuString.length-1);
			
			location.href="SysServlet?command=grant&menuString="+menuString+"&roleId=${param.roleId}";
		});
	});
</script>
</head>
<body>
	<fieldset style="width:40%">
		<legend>角色授权操作[${param.roleId}]</legend>
		<ul>
			<c:forEach items="${mainMenus }" var="mainMenu">
				<li>
					<c:set var="flag" value="true" />
					<c:forEach items="${roleMainMenus }" var="roleMainMenu">
						<c:if test="${roleMainMenu.rightId==mainMenu.rightId }">
							<input type="checkbox" checked="checked" name="main" id="main${mainMenu.rightId }" value="${mainMenu.rightId }" /><label for="main${mainMenu.rightId }">${mainMenu.rightname}</label>
							<c:set var="flag" value="false" />
						</c:if>
					</c:forEach>
					<c:if test="${flag}">
						<input type="checkbox" name="main" id="main${mainMenu.rightId }" value="${mainMenu.rightId }" /><label for="main${mainMenu.rightId }">${mainMenu.rightname}</label>
					</c:if>
					<ul class="child">
						<c:forEach items="${childMenus }" var="childMenu">
							<c:if test="${childMenu.parentId == mainMenu.rightId }">
								<li>
									<c:set var="flag" value="true" />
									<c:forEach items="${roleChildMenus }" var="roleChildMenu">
										<c:if test="${roleChildMenu.rightId== childMenu.rightId }">
											<input type="checkbox" checked="checked" name="child" id="child${childMenu.rightId }" value="${childMenu.rightId }" /><label for="child${childMenu.rightId }">${childMenu.rightname}</label>
											<c:set var="flag" value="false" />
										</c:if>
									</c:forEach>
									<c:if test="${flag }">
										<input type="checkbox" name="child" id="child${childMenu.rightId }" value="${childMenu.rightId }" /><label for="child${childMenu.rightId }">${childMenu.rightname}</label>
									</c:if>
								</li>
							</c:if>
						</c:forEach>
					</ul>
						
				</li>
			</c:forEach>
		</ul>
		<input type="button" value="授权" />
	</fieldset>
</body>
</html> --%>